package com.course.serviceImpl;

import com.course.daoI.SecurityDAOI;
import com.course.daoImpl.SecurityDAOImpl;
import com.course.exception.ConnectionException;
import com.course.exception.DataNotFoundException;
import com.course.exception.LoginException;
import com.course.formbean.ProfileFormBean;
import com.course.serviceI.SecurityServiceI;

public class SecurityServiceImpl implements SecurityServiceI{
	
	
	SecurityDAOI sdao=new SecurityDAOImpl();
	boolean flag=false;
	
	String data="";

	public boolean changePassword(ProfileFormBean regbean)
			throws LoginException, ConnectionException {
		
		flag=sdao.changePassword(regbean);
		if(flag==false)
		{
			throw new ConnectionException();
			}
       else if(regbean==null) {
			throw new LoginException();
			}
		return flag;
		
		
	}

	public boolean changeQuestion(ProfileFormBean regbean)
			throws LoginException, ConnectionException {
		
		
		flag=sdao.changeQuestion(regbean);
		
		if(flag==false)
		{
			throw new ConnectionException();
			}
       else if(regbean==null) {
			throw new LoginException();
			}
		return flag;
	}

	public String checkUser(String userName) throws DataNotFoundException,
	LoginException {
		
		
		data=sdao.checkUser(userName);
		
		if(data==null)
		{
			throw new DataNotFoundException();
			}
       else if(userName==null) {
			throw new LoginException();
			}
		return data;
		
		
		
	}

	public String loginCheck(ProfileFormBean regbean)
			throws DataNotFoundException, LoginException {
		
		
		data=sdao.loginCheck(regbean);
		if(data==null)
		{
			throw new DataNotFoundException();
			}
       else if(regbean==null) {
			throw new LoginException();
			}
		return data;
		
		
	}

	public void loginaudit(String loginid) throws LoginException{
		
		sdao.loginaudit(loginid);
		if(loginid==null){
			throw new LoginException();
			}
		
	}

	public String recoverPasswordByQuestion(ProfileFormBean regbean)
			throws DataNotFoundException, LoginException {
		
		data=sdao.recoverPasswordByQuestion(regbean);
		if(data==null)
		{
			throw new DataNotFoundException();
			}
       else if(regbean==null) {
			throw new LoginException();
			}
		return data;
		
		
	}
	public boolean checkAvailability(String userid){
		return sdao.checkAvailability(userid);
		
	}

}
